﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AwesomeEnginePC.Inputs
{
    public enum MouseButtons
    {
        LeftClick,
        RightClick,
        ScrollWheel,
        BackButton,
        ForwardButton,
    }

    public class MouseInputs : BaseInput
    {
        private MouseState _prevMouseState;

        public override List<object> JustPressedButtons()
        {
            List<object> returnButtons = new List<object>();
            MouseState currentState = Mouse.GetState();

            if (currentState.LeftButton == ButtonState.Pressed && _prevMouseState.LeftButton == ButtonState.Released) returnButtons.Add(MouseButtons.LeftClick);
            if (currentState.RightButton == ButtonState.Pressed && _prevMouseState.RightButton == ButtonState.Released) returnButtons.Add(MouseButtons.RightClick);
            if (currentState.MiddleButton == ButtonState.Pressed && _prevMouseState.MiddleButton == ButtonState.Released) returnButtons.Add(MouseButtons.ScrollWheel);
            if (currentState.XButton1 == ButtonState.Pressed && _prevMouseState.XButton1 == ButtonState.Released) returnButtons.Add(MouseButtons.ForwardButton);
            if (currentState.XButton2 == ButtonState.Pressed && _prevMouseState.XButton2 == ButtonState.Released) returnButtons.Add(MouseButtons.BackButton);

            return returnButtons;
        }

        public override Dictionary<object, ButtonState> GetStates()
        {
            Dictionary<object, ButtonState> returnStates = new Dictionary<object, ButtonState>();
            MouseState currentState = Mouse.GetState();

            returnStates[MouseButtons.LeftClick] = currentState.LeftButton;
            returnStates[MouseButtons.RightClick] = currentState.RightButton;
            returnStates[MouseButtons.ScrollWheel] = currentState.MiddleButton;
            returnStates[MouseButtons.ForwardButton] = currentState.XButton1; //might be reversed
            returnStates[MouseButtons.BackButton] = currentState.XButton2;

            return returnStates;
        }

        public override void Update(GameTime gameTime)
        {
            _prevMouseState = Mouse.GetState();
        }
    }
}
